package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.domain.Cart;
import org.csu.mypetstore.domain.Order;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/guidetiship")
public class Guidetiship extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Order order = new Order();
        Account account = (Account) req.getSession().getAttribute("account");
        Cart cart = (Cart) req.getSession().getAttribute("cart");
        order.initOrder(account, cart);
        req.getSession().setAttribute("order",order);
        req.getRequestDispatcher("/WEB-INF/jsp/order/ShippingForm.jsp").forward(req,resp);
    }
}
